package com.benchproject.persist;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Example;

import com.benchproject.domainmodel.Account;
import com.benchproject.domainmodel.User;

@Repository("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
	
	
    /**
     * @see com.benchproject.persist.UserDao#getUserForCode(String)
     */
    public User getUserForId(Long id) {
//          return getUserForDetatchedCriteria(code);
        List<User> results = getHibernateTemplate().find("from User where id = ?", id);
        return results.get(0);
    }

    /**
     * @see com.benchproject.persist.UserDao#getAllUsers()
     */
    public List<User> getAllUsers() {
        return getHibernateTemplate().loadAll(User.class);
    }


    /**
     * todo - (Nice to have) Hibernates findByExample way of retrieving object
     */
    public User getUserForExample(String code){
//        User searchObj = new User();
////        searchObj.setName(code);
//        List<User> results = getHibernateTemplate().findByExample(searchObj);        
//        return results.get(0);
    	return null;
    }

    /**
     * todo - (Nice to have) Hibernates DetatchedCriteria way of retrieving object
     */
    public User getUserForDetatchedCriteria(String code){
//        User searchObj = new User();
//        searchObj.setCode(code);
//        searchObj.setName("American Airlines");
//        Example example = Example.create(searchObj);
//        example.excludeProperty("code");
//        example.excludeNone();
//        DetachedCriteria criteria = DetachedCriteria.forClass(User.class).add(example);
//        List<User> results = getHibernateTemplate().findByCriteria(criteria);
//        return results.get(0);
    	return null;
    }

}
